package com.gameShare.controller.user

import com.gameShare.controller.base.LoginVerifyController
import com.gameShare.entity.vo.ResponseVo
import com.gameShare.service.user.UserCommentLikeService
import jakarta.servlet.http.HttpServletRequest
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("userLike")
class UserLikeController(
    private val userCommentLikeService: UserCommentLikeService
) : LoginVerifyController() {


    /**
     * 点赞操作
     *
     * @param httpServletRequest 请求体
     * @param gameId 游戏id
     * @param commentId 评论id
     * @return 请求成功
     */
    @PostMapping("like")
    fun like(httpServletRequest : HttpServletRequest,
             @RequestParam(required = true) gameId : String,
             @RequestParam(required = true) commentId : Int
    ): ResponseVo<Boolean> {
        return getSuccessResponseVO(
            userCommentLikeService
                    .like(
                        gameId,
                        commentId,
                        getUserIdByToken(httpServletRequest)
            )
        )
    }

    /**
     * 取消点赞
     *
     * @param httpServletRequest 请求头
     * @param gameId 游戏id
     * @param commentId 评论id
     * @return
     */
    @RequestMapping("cancelLike")
    fun cancelLike(httpServletRequest: HttpServletRequest, gameId: String, commentId: Int): ResponseVo<Boolean> {
        return getSuccessResponseVO(
            userCommentLikeService
                    .cancelLike(
                        gameId,
                        commentId,
                        getUserIdByToken(httpServletRequest)
            )
        )
    }

    /**
     * 加载
     *
     * @param httpServletRequest
     * @param gameId
     * @return
     */
    @RequestMapping("loadAllLikeComment")
    fun loadAllLikeComment(httpServletRequest: HttpServletRequest, gameId: String): ResponseVo<List<String>> {
        return getSuccessResponseVO(
            userCommentLikeService
                    .loadAllLikeCommentByGameId(
                        gameId,
                        getUserIdByToken(httpServletRequest)
            )
        )
    }
}